package net.sudot.chess.business.service;

import net.sudot.chess.business.dao.ChatRecordDao;
import net.sudot.chess.business.dto.ChatMessageDTO;
import net.sudot.chess.business.model.ChatRecord;
import net.sudot.chess.business.model.RoomCustomerRef;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.util.List;

/**
 * 游戏
 *
 * @author tangjialin on 2018-02-27.
 */
@Service
public class ChatRecordService extends BaseService<ChatRecord> {

    @Resource
    private ChatRecordDao chatRecordDao;
    @Resource
    private RoomCustomerRefService roomCustomerRefService;

    /**
     * 获取聊天室某个玩家加入后的聊天信息
     *
     * @param roomId     房间主键
     * @param customerId 游戏玩家主键
     * @return 返回聊天信息
     */
    public List<ChatMessageDTO> findListByRoomAtAfter(Long roomId, Long customerId) {
        RoomCustomerRef customerRef = roomCustomerRefService.findByRoomAndCustomer(roomId, customerId);
        return chatRecordDao.findListByRoomAtAfter(roomId, customerRef.getCreatedDate());
    }

    /**
     * 获取房间下指定时间后的聊天信息
     *
     * @param roomId    房间主键
     * @param startDate 指定的起始时间
     * @return 返回聊天信息
     */
    public List<ChatMessageDTO> findListByRoomAtAfter(Long roomId, Instant startDate) {
        return chatRecordDao.findListByRoomAtAfter(roomId, startDate);
    }
}
